package com.sy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @className: CorsConfig
 * @author: Mr.Liu
 * @date: 2025/10/29 10:34
 * @Version: 1.0
 * @description: 解决跨域问题
 */
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //请求映射
                .allowedMethods("POST","GET","DELETE","PUT","OPTIONS") //允许的请求方式
                 //必须写固定，具体的
                .allowedOrigins("http://localhost:5173", //允许的web前端项目
                        "https://s.apifox.cn") //允许的ApifoxWeb端的接口测试
                .allowedHeaders("*")
                .allowCredentials(true)  //允许携带凭证 cookie,token
                .maxAge(3600);
    }
}
